﻿/*
cd /projects/hsieh_project/proj_201809/code_1_data/
qsas data_1_fknaics_sum.sas 5 &
*/

/*
Author: Adarsh Kumar
Objective: Industry level stats (total employment, top 10% employment, top 10% establishment count), 
where industry is defined using fknaics, naics, sic.
*/

libname hr "/projects/hsieh_project/proj_201809/data/";

%Let dir_out = /projects/hsieh_project/proj_201809/data/;

/*---------------------------------------------------------*/
/* Load Raw Data: Loading only 1977-2013 LBD Data w/o czone, msacz to speed up process
/*---------------------------------------------------------*/

%include "/projects/hsieh_project/proj_201809/code_1_data/m_read.sas" /source2;
%m_read(param_dev=1,param_lyear=1977 2001 2002 2013,param_czone=0,param_msa1983=1,param_msacz=0,param_drop=1);

%include "/projects/hsieh_project/code_0_general/m_perc_by_var.sas" /source2;

/* Load macro in data_0_fknaics_sum.sas: */
%include "/projects/hsieh_project/proj_201809/code_1_data/data_0_fknaics_sum.sas" /source2;

/*C Macro: */

%fknaics_ind_sum(dt_in = lbd, dt_out = lbd_fknaics_est, group_var = fk_naics, years = 1977 2013, ivar=lbdid, ivaro=n_est, vperc = mkt);

%fknaics_ind_sum(dt_in = lbd, dt_out = lbd_naics_est, group_var = naics, years = 2002 2013, ivar = lbdid, ivaro = n_est, vperc = mkt);

%fknaics_ind_sum(dt_in = lbd, dt_out = lbd_sic_est, group_var = sic, years = 1977 2001, ivar = lbdid, ivaro = n_est, vperc = mkt);

proc export data = lbd_fknaics_est outfile="&dir_out./fknaics_sum_all_top_est.dta" replace;
run;

proc export data = lbd_naics_est outfile="&dir_out./naics_sum_all_top_est.dta" replace;
run;

proc export data = lbd_sic_est outfile="&dir_out./sic_sum_all_top_est.dta" replace;
run;

%fknaics_ind_sum(dt_in = lbd, dt_out = lbd_fknaics_emp, group_var = fk_naics, years = 1977 2013, ivar=worker, ivaro= worker, vperc = worker);

%fknaics_ind_sum(dt_in = lbd, dt_out = lbd_naics_emp, group_var = naics, years = 2002 2013, ivar = worker, ivaro = worker, vperc = worker);

%fknaics_ind_sum(dt_in = lbd, dt_out = lbd_sic_emp, group_var = sic, years = 1977 2001, ivar = worker, ivaro = worker, vperc = worker);

proc export data = lbd_fknaics_emp outfile="&dir_out./fknaics_sum_all_top_emp.dta" replace;
run;

proc export data = lbd_naics_emp outfile="&dir_out./naics_sum_all_top_emp.dta" replace;
run;

proc export data = lbd_sic_emp outfile="&dir_out./sic_sum_all_top_emp.dta" replace;
run;


/* Call by sector for Appendix 3 */
%fknaics_ind_sum(dt_in = lbd, dt_out = lbd_sector_emp, group_var = sector, years = 1977 2013, ivar=worker, ivaro= worker, vperc = worker);

%fknaics_ind_sum(dt_in = lbd, dt_out = lbd_sector_est, group_var = sector, years = 1977 2013, ivar=lbdid, ivaro=n_est, vperc = mkt);

proc export data = lbd_sector_emp outfile="&dir_out./sector_sum_all_top_emp.dta" replace; 
run;

proc export data = lbd_sector_est outfile="&dir_out./sector_sum_all_top_est.dta" replace; 
run;

/* End of SAS file */
